import { get, post } from '../ajax'
import { getAjaxBaseUrl } from '../handler'

const controller = getAjaxBaseUrl(
  '/energyMetrologicalReview',
  '/energy',
)

/**
 * 新增或修改能源计量人员信息
 * @field isTrain: 0 否，1 是
 * @field type: 1 正常数据，2 填报表单信息
 */
export function saveOrUpdateMetrologyPersonnel(list: Partial<{
  id: number
  personnelName: string
  departmental: string
  duties: string
  specialityDuties: string
  isTrain: 1 | 2
  certificateNumber: string
  remarks: string
  type: 1 | 2
  personInCharge: string
  informer: string
  telephone: string
  fillInDate: string
  dataTime: string
}>[]) {
  return post(
    `${controller}/saveOrUpdateMetrologyPersonnel`,
    list,
  )
}

/** 查询能源计量人员信息 */
export function selectMetrologyPersonnel(dataTime: string) {
  return get(`${controller}/selectMetrologyPersonnel`, {
    dataTime,
  })
}

/**
 * 新增或修改主要用能设备信息
 * @field type: 1 正常数据，2 填报表单信息
 */
export function saveOrUpdateKeyDevice(list: Partial<{
  id: number
  departmental: string
  deviceName: string
  deviceNumber: string
  deviceModel: string
  installationLocation: string
  useEnergyType: string
  devicePower: number
  remarks: string
  type: 1 | 2
  personInCharge: string
  informer: string
  telephone: string
  fillInDate: string
  dataTime: string
}>[]) {
  return post(`${controller}/saveOrUpdateKeyDevice`, list)
}

/** 查询主要用能设备信息 */
export function selectKeyDevice(dataTime: string) {
  return get(`${controller}/selectKeyDevice`, {
    dataTime,
  })
}

/**
 * 新增或修改设备的计量器具配备信息
 * @field gradeType 能源计量分级、分项 1 进出用能单位，2 进出主要次级用能单位，3 主要用能设备，4 其他项目
 * @field toolsType 计量器具类别 1 衡器，2 电能表，3 油流量表，4 气流量表，5 水流量表，6 温度仪表，7 压力仪表
 */
export function saveOrUpdateToolsAllocate(list: Partial<{
  id: number
  gradeType: number
  gradeName: string
  shouldEquipped1: number
  realityEquipped1: number
  shouldEquipped2: number
  realityEquipped2: number
  shouldEquipped3: number
  realityEquipped3: number
  shouldEquipped4: number
  realityEquipped4: number
  shouldEquipped15: number
  realityEquipped5: number
  shouldEquipped6: number
  realityEquipped6: number
  shouldEquipped7: number
  realityEquipped7: number
  type: 1 | 2
  personInCharge: string
  informer: string
  telephone: string
  fillInDate: string
  dataTime: string
}>[]) {
  return post(`${controller}/saveOrUpdateToolsAllocate`, list)
}

/** 查询设备的计量器具配备信息 */
export function selectToolsAllocate(dataTime: string) {
  return get(`${controller}/selectToolsAllocate`, {
    dataTime,
  })
}

/**
 * 新增或修改能源计量分级、分项信息
 * @field gradeType 能源计量分级、分项 1 进出用能单位，2 进出主要次级用能单位，3 主要用能设备，4 其他项目
 */
export function saveOrUpdateMeasurementClassification(list: Partial<{
  id: number
  energyName: string
  gradeType: number
  shouldEquipped: number
  realityEquipped: number
  type: 1 | 2
  personInCharge: string
  informer: string
  telephone: string
  fillInDate: string
  dataTime: string
}>[]) {
  return post(
    `${controller}/saveOrUpdateMeasurementClassification`,
    list,
  )
}

/** 查询能源计量分级、分项信息 */
export function selectMeasurementClassification(dataTime: string) {
  return get(`${controller}/selectMeasurementClassification`, {
    dataTime,
  })
}

/** 新增或修改计量器具准确度等级统计信息 */
export function saveOrUpdateToolsAccuracyClass(list: Partial<{
  id: number
  measurementPurpose: number
  accuracyClassAsk1: string
  realityAccuracyClass1: string
  accuracyClassAsk2: string
  realityAccuracyClass2: string
  accuracyClassAsk3: string
  realityAccuracyClass3: string
  accuracyClassAsk4: string
  realityAccuracyClass4: string
  type: 1 | 2
  personInCharge: string
  informer: string
  telephone: string
  fillInDate: string
  dataTime: string
}>[]) {
  return post(
    `${controller}/saveOrUpdateToolsAccuracyClass`,
    list,
  )
}

/** 查询计量器具准确度等级统计信息 */
export function selectToolsAccuracyClass(dataTime: string) {
  return get(`${controller}/selectToolsAccuracyClass`, {
    dataTime,
  })
}

/** 新增或修改能源计量器具分表信息 */
export function saveOrUpdateMeasuringTools(list: Partial<{
  id: number | string
  name: number
  type: 1 | 2 | 3 | 4
  specification: string
  accuracyLevel: string
  measuringRange: string
  factory: string
  factoryNumber: string
  useUnitNumber: string
  installationLocation: string
  effectiveTime: string
  status: 1 | 2 | 3
  verificationCycle: string
}>[]) {
  return post(`${controller}/saveOrUpdateMeasuringTools`, list)
}

/** 查询能源计量器具分表信息 */
export function selectMeasuringTools(type?: 1 | 2 | 3 | 4) {
  return get(`${controller}/selectMeasuringTools`, {
    type,
  })
}

/** 保存或更新年度能源消费结构信息 */
export function saveOrUpdateEnergyConsumptionStructure(list: Partial<{
  energyName: string
  unitOfMeasurement: string
  code: string
  beginningInventory: string
  physicalQuantity: string
  amount: string
  total: string
  industrialProduction: string
  forRawMaterials: string
  nonIndustrialProduction: string
  transportationConsumption: string
  endingInventory: string
  useScalingFactor: string
  referenceDiscountFactor: string
  year: string
}>[]) {
  return post(
    `${controller}/saveOrUpdateEnergyConsumptionStructure`,
    list,
  )
}

/** 查询能源消费结构信息 */
export function loadYearEnergyConsumptionStructure(year: string) {
  return get(`${controller}/loadYearEnergyConsumptionStructure`, {
    year,
  })
}
